const { defineConfig } = require('@vue/cli-service');

function mock(app, url, data) {
  app.get(url, (request, response) => {
    response.json(data);
  });
}

const homeData = require('./src/mock/bookHome');
const shelfData = require('./src/mock/bookShelf');
const listData = require('./src/mock/bookList');
const flatListData = require('./src/mock/bookFlatList');

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  devServer: {
    onBeforeSetupMiddleware: (devServer) => {
      const app = devServer.app;
      mock(app, '/book/home', homeData);
      mock(app, '/book/shelf', shelfData);
      mock(app, '/book/list', listData);
      mock(app, '/book/flatList', flatListData);
    },
  },
});
